#include "stdafx.h"
#include "monster.h"

void CMonster::MonsterAI(Character& chr,float TimePass)
{

	if(IsDead())
	{
		Zero();
		return;
	}
	
	float ATK = 1;
	float M = 30*TimePass;
	float L = Getline(chr);
	float P = (chr.GetX()-GetX())/L*M;
	float Q = (chr.GetY()-GetY())/L*M;

	if(L < 200)
	{	
		if( L < 60 )
		{
			chr.BeAttack(ATK);
			CurActionSystem.ChangeAction(300);
			FaceDir(chr.GetX(),chr.GetY());
			CurActionSystem.CurActionTime = 0 ;
			CurActionSystem.bMonsterChangeAction = true;
			return;
		}else if (L < M)
		{
			SetShift(chr.GetX(),chr.GetY());
			if(CurActionSystem.GetCurAction().ID != 110)
			{
				CurActionSystem.ChangeAction(110);
				FaceDir(chr.GetX(),chr.GetY());
				CurActionSystem.CurActionTime = 0 ;
				CurActionSystem.bMonsterChangeAction = true;
				return;
			}
			else if(CurActionSystem.GetCurAction().ID == 110)
			{	
				CurActionSystem.bMonsterChangeAction = false;
				CurActionSystem.CurActionTime = 0 ;
				return;			
			}
		}
		else
		{
			Shift(P,Q);
			if(CurActionSystem.GetCurAction().ID != 110)
			{
				CurActionSystem.ChangeAction(110);
				FaceDir(chr.GetX(),chr.GetY());
				CurActionSystem.CurActionTime = 0 ;
				CurActionSystem.bMonsterChangeAction = true;
				return;
			}
			else if(CurActionSystem.GetCurAction().ID == 110)
			{
				CurActionSystem.bMonsterChangeAction = false;
				CurActionSystem.CurActionTime = 0 ;
				return;
			}
		}
	}
	
	CurActionSystem.bMonsterChangeAction = false;
	CurActionSystem.CurActionTime = 0 ;
}
	
